package cn.jsj.dispose;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 律师提成处理类
 * @author LI
 *
 */
 public class LawyerRoyaltyRequest extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//调试信息
		 cn.jsj.utils.SysLogger.PrintInfo("律师提成处理类！！！");

		 //获得参数
		 String contractMoney=request.getParameter("rContractMoney").trim();
		 String lawyercontractId=request.getParameter("LawyercontractId").trim();
		 String lawyerName=request.getParameter("rLawyerName").trim();
		 String royaltyTime=request.getParameter("royaltyTime").trim();
		 String royaltyMoney=request.getParameter("royaltyMoney").trim();
		 String royaltyRemark=request.getParameter("royaltyRemark").trim();
		 //密码当做签名用
		 String passWord=request.getParameter("passWord").trim();

		 //判断签名是否合法，即密码是否正确
		 	cn.jsj.dao.TblLawyerDAO tld=new cn.jsj.dao.TblLawyerDAO();
		 	//1：签名有效 0：签名无效
		 	int validate=tld.signedVerify(lawyerName, passWord);

		 	//输出流
		 	java.io.PrintWriter out=response.getWriter();
		 	//如果签名无效
		 	if(validate==0){
		 		out.println("{message:'签名无效'}");
		 		out.flush();
		 		out.close();
		 		return;
		 	}

		 	//判断用户输入的的提出金额是否大于合同金额的80%

		 	//先获取提成总金额
		 	cn.jsj.dao.TblRoyaltyInfoDAO trid=new cn.jsj.dao.TblRoyaltyInfoDAO();
		 	int totalRoyaltyMoney=trid.getRoyaltyMoney(lawyercontractId);
		 	//如果大于80%
		 	double contractPercent=Integer.parseInt(contractMoney)*0.8;
		 	double totalRoyalty=(totalRoyaltyMoney+Integer.parseInt(royaltyMoney));

		 	cn.jsj.utils.SysLogger.PrintInfo(" "+totalRoyalty+"   "+contractPercent);
		 	if(totalRoyalty>contractPercent){
		 		out.println("{message:'律师提成超过了80%！'}");
		 		out.flush();
		 		out.close();
		 		return;
		 	}
		 //调试信息
		 cn.jsj.utils.SysLogger.PrintInfo("canshu ---------->"+lawyercontractId+"     "+royaltyTime+"     "+royaltyMoney+"     "+royaltyRemark+"     "+passWord+"       "+lawyerName);
		 //判断备注是否为NULL
		 if(royaltyRemark.length()==0);
		 {
			 royaltyRemark="没有";
		 }
		 //保存提成信息
		  int saveResult=trid.lawyerRoyaOperation(lawyercontractId, royaltyTime, royaltyMoney, royaltyRemark);

		  //如果保存成功
		   if(saveResult==1){
			   out.println("{message:'提成成功！'}");
		   }
		   else{
			   out.println("{message:'提成失败！'}");
		   }
		   out.flush();
		   out.close();


	 }
	 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}
}